package project.mafia.frame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JPanel;


/**
 *
 * @author
 * RakuSe7en
 */
public class Vote extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5310870865471334880L;
	private String[] user;
	private int result;
	private JDialog dialog;
	public Vote(String[] user, JDialog dialog) {
		this.user = user;
		this.dialog = dialog;
		initComponents();
	}
	@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
	private void initComponents() {

		setSize(100,150);
		buttonGroup1 = new javax.swing.ButtonGroup();
		buttonGroup2 = new javax.swing.ButtonGroup();
		buttonGroup3 = new javax.swing.ButtonGroup();
		buttonGroup4 = new javax.swing.ButtonGroup();
		jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
		jScrollPane1 = new javax.swing.JScrollPane();
		userList = new javax.swing.JList();
		voteBtn = new javax.swing.JButton();

		jRadioButtonMenuItem1.setSelected(true);
		jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");

		userList.setModel(new javax.swing.AbstractListModel() {
			public int getSize() { return user.length; }
			public Object getElementAt(int i) { return user[i]; }
		});
		
		
		jScrollPane1.setViewportView(userList);

		voteBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				result = userList.getSelectedIndex();
				dialog.setVisible(false);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jScrollPane1)
								.addComponent(voteBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE))
								.addContainerGap())
				);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(voteBtn)
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);
	}// </editor-fold>                        
	public int getResult() {
		return result;
	}
	public void setTimer(String s){
		voteBtn.setText(s);
	}
	// Variables declaration - do not modify                     
	private javax.swing.ButtonGroup buttonGroup1;
	private javax.swing.ButtonGroup buttonGroup2;
	private javax.swing.ButtonGroup buttonGroup3;
	private javax.swing.ButtonGroup buttonGroup4;
	private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JList userList;
	private javax.swing.JButton voteBtn;
	// End of variables declaration                   
}
